package at.fhooe.stefanirndorfer.util;

import java.nio.FloatBuffer;

import org.lwjgl.BufferUtils;

import at.fhooe.stefanirndorfer.engine.game.Game;
import at.fhooe.stefanirndorfer.sound.SoundListener;

/**
 * simple util class to define an openAL listener
 * @author stefanirndorfer
 *
 */
public class AudioListener implements SoundListener{

	private FloatBuffer listenerPos;
	private FloatBuffer listenerVel;
	private FloatBuffer listenerOri;

	public AudioListener(){
		initAudioStuff();
		setSoundListener();
	}
	
	
	private void initAudioStuff() {
		initSoundListenerPosition();
		initSoundListenerOrientation();
		initSoundListenerVelocity();
	}

	@Override
	public void initSoundListenerPosition() {
		listenerPos = (FloatBuffer)BufferUtils.createFloatBuffer(3).put(new float[] { 0.0f, 0.0f, 0.0f }).rewind();
	}

	@Override
	public void initSoundListenerVelocity() {
		listenerVel = (FloatBuffer)BufferUtils.createFloatBuffer(3).put(new float[] { 0.0f, 0.0f, 0.0f }).rewind();
		
	}

	@Override
	/** Orientation of the listener. (first 3 elements are "at", second 3 are "up") */
	public void initSoundListenerOrientation() {
		listenerOri = (FloatBuffer)BufferUtils.createFloatBuffer(6).put(new float[] { 0.0f, 0.0f, -1.0f,  0.0f, 1.0f, 0.0f }).rewind();
		//listenerOri = (FloatBuffer)BufferUtils.createFloatBuffer(6).put(new float[] { 0.0f, 0.0f, 0.0f,  0.0f, 1.0f, 0.0f }).rewind();
	}



	@Override
	public FloatBuffer getPosition() {
		return listenerPos;
	}



	@Override
	public FloatBuffer getVelocity() {
		return listenerVel;
	}


	@Override
	public FloatBuffer getOrientation() {
		return listenerOri;
	}



	@Override
	public void setSoundListener() {
		Game.getInstance().getSoundManager().registerListener(this);
	}

	

}
